package org.htmlparser.filters;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.htmlparser.Node;
import org.htmlparser.NodeFilter;
import org.htmlparser.Text;

public class RegexFilter
  implements NodeFilter
{
  public static final int FIND = 3;
  public static final int LOOKINGAT = 2;
  public static final int MATCH = 1;
  protected Pattern mPattern;
  protected String mPatternString;
  protected int mStrategy;

  public RegexFilter()
  {
    this(".*", 3);
  }

  public RegexFilter(String paramString)
  {
    this(paramString, 3);
  }

  public RegexFilter(String paramString, int paramInt)
  {
    setPattern(paramString);
    setStrategy(paramInt);
  }

  public boolean accept(Node paramNode)
  {
    Matcher localMatcher;
    boolean bool = false;
    if (paramNode instanceof Text)
    {
      String str = ((Text)paramNode).getText();
      localMatcher = this.mPattern.matcher(str);
      switch (this.mStrategy)
      {
      default:
        bool = localMatcher.find();
      case 1:
      case 2:
      }
    }
    while (true)
    {
      while (true)
      {
        return bool;
        bool = localMatcher.matches();
      }
      bool = localMatcher.lookingAt();
    }
  }

  public String getPattern()
  {
    return this.mPatternString;
  }

  public int getStrategy()
  {
    return this.mStrategy;
  }

  public void setPattern(String paramString)
  {
    this.mPatternString = paramString;
    this.mPattern = Pattern.compile(paramString);
  }

  public void setStrategy(int paramInt)
  {
    if ((paramInt != 1) && (paramInt != 2) && (paramInt != 3))
      throw new IllegalArgumentException("illegal strategy (" + paramInt + ")");
    this.mStrategy = paramInt;
  }
}